﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AnalysisSystemLog.Define
{
    public class SystemEventLog
    {
        private EventLogEntryCollection eventCollection;
        private EventLog systemEvent;

        public SystemEventLog()
        {
            systemEvent = new EventLog();
            systemEvent.Log = "System";
            eventCollection = systemEvent.Entries;
        }

        /** 系统日志数据结构**/
        public struct EventLogData
        {
            public int EventID;
            public DateTime TimeGenerated;
        }

        /** 系统日志数据结构**/
        public List<EventLogData> EventLogDataList;

        /** 
         * \brief 获取系统日志数据
         * 
         * \param iNumbers  输入数据
         */
        public void GetRecords(params int[] iNumbers)
        {
            EventLogDataList = new List<EventLogData>();
            foreach (EventLogEntry v in systemEvent.Entries)
            {
                EventLogEntry entry = v;
                foreach (var i in iNumbers)
                {

                    if (v.EventID == i)
                    {
                        EventLogData s = new EventLogData();
                        s.TimeGenerated = v.TimeGenerated;
                        s.EventID = v.EventID;

                        EventLogDataList.Add(s);
                    }
                }
            }
        }

        /** 
         * \brief 系统日志数据结构
         */
        //public EventLogEntryCollection LoadEventLog()
        //{
           // EventLog systemEvent = new EventLog();
           // systemEvent.Log = "System";
           // eventCollection = systemEvent.Entries;
           // return eventCollection;
           // int length = eventCollection.Count;
           // EventLogEntry entry = eventCollection[c];
           // string[] title ={
           // entry.EntryType.ToString(),
           // entry.TimeGenerated.ToLongDateString(),
           // entry.TimeGenerated.ToLongTimeString(),
           // entry.Source,
           // entry.Category,
           // //entry.EventID.ToString(),
           // entry.InstanceId.ToString(),
           // entry.UserName,
           // entry.MachineName
           //};
           // for (int j = 0; j < title.Length; j++)
           // {
                //Console.WriteLine(title[j]);
            //    MessageBox.Show(title[j]);
            //}
            //Console.WriteLine("n" + eventCollection[c].Message);
        //}

        /** 
         * \breif 系统日志数据结构 
         */
        public string DisplayEventCount()
        {
            return (eventCollection.Count.ToString());
        }
    }

    /** 系统事件代码 **/
    public enum SystemEventCode
    {
        Start = 6009,          // 开机
        Shutdown = 6006,   // 关机
        Logon = 4624,       // 登录
    }
}
